<template>
    <div class="container">
        <div class="title">
            <span>设置取送员</span>
            <span class="back" @click="back">
        <i class="iconfont icon-fanhui"></i> 返回
      </span>
        </div>
        <el-divider></el-divider>
        <br/>
        <el-form label-width="120px"
                 :model="form"
                 status-icon
                 ref="form"
                 @submit.native.prevent>
            <el-form-item label="分店" prop="lin_user_id">
                <el-select  size="medium" filterable v-model="form.lin_user_id" placeholder="请选择分店" clearable>
                    <el-option
                        v-for="(admin, index) in adminArr"
                        :key="index"
                        :label="admin.username"
                        :value="admin.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="姓名" prop="name">
                <el-input size="medium" v-model="form.name" placeholder="请填写取送员姓名"></el-input>
            </el-form-item>
            <el-form-item label="电话" prop="phone">
                <el-input size="medium" type="number" v-model="form.phone" placeholder="请填写取送员电话"></el-input>
            </el-form-item>
            <el-form-item class="submit">
                <el-button type="primary" @click="submitForm('form')">保 存</el-button>
                <el-button @click="resetForm('form')">重 置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import staff from '@/models/staff'
import admin from '@/models/admin'

export default {
  props: {
    userId: {
      type: Number,
    },
  },
  data() {
    return {
      adminArr: [],
      form: {
        name: '',
        phone: '',
        lin_user_id: '',
      },
    }
  },
  mounted() {
    this.getAdminAll()
  },
  methods: {
    async getAdminAll() {
      this.adminArr = await admin.getAdminAll()
    },
    // eslint-disable-next-line no-unused-vars
    async submitForm(formName) {
      const self = this
      // eslint-disable-next-line no-unused-vars
      const info = {
        user_id: this.userId,
        name: self.form.name,
        phone: self.form.phone,
        lin_user_id: self.form.lin_user_id,
      }
      try {
        // eslint-disable-next-line no-unused-vars
        const res = await staff.createStaff(info)
        if (res.error_code === 0) {
          this.$message.success(`${res.msg}`)
          this.back()
        }
      } catch (error) {
        console.log(error)
      }
    },
    // 重置表单
    resetForm() {
      this.getInfo()
    },
    back() {
      this.$emit('editClose')
    },
  },
}
</script>

<style lang="scss" scoped>
    .el-divider--horizontal {
        margin: 0
    }

    .container {
        .title {
            height: 59px;
            line-height: 59px;
            color: $parent-title-color;
            font-size: 16px;
            font-weight: 500;
            text-indent: 40px;

            .back {
                float: right;
                margin-right: 40px;
                cursor: pointer;
            }
        }

        .wrap {
            padding: 20px;
        }

        .submit {
            float: left;
        }
    }
</style>
